<template>
	<view class="add-game-container">
		<view class="game-list">
			<view class="game-item" v-for="(item, index) in gameList" :key="item.name">
				<view class="rank">#{{ index + 1 }}</view>
				<image :src="item.picture" class="game-image"></image>
				<view class="game-info">
					<view class="game-name"
						>{{ item.name }}<u-tag :text="item.tag" size="mini" :bgColor="themeColor" :borderColor="themeColor"></u-tag
					></view>
					<u-rate :value="item.point / 2" :active-color="themeColor" inactive-color="#999" size="14" readonly allowHalf></u-rate>
					<view class="game-desc">
						<view class="game-desc-item"><u-icon name="tags" color="#999" size="14"></u-icon>{{ item.difficulty }}</view>
						<view class="game-desc-item"><u-icon name="account" color="#999" size="14"></u-icon>{{ item.players }}</view>
						<view class="game-desc-item"><u-icon name="clock" color="#999" size="14"></u-icon>{{ item.time }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import request from '@/api/http.js';

export default {
	data() {
		return {
			gameList: [],
		};
	},
	onShow() {
		this.getGameList();
	},
	methods: {
		async getGameList() {
		    const res = await request(`/game/page`);
			let gameList = res.data.list;
			// 全部游戏
			gameList = gameList.map(item => {
				return {
					...item,
					// difficulty: difficultyMap[item.difficulty],
					tag: item.types.split('|')[0]
				}
			})
			this.gameList = gameList;
		}
	}
};
</script>

<style lang="scss">
.game-list {
	display: flex;
	flex-direction: column;
	gap: 20rpx;

	.game-item {
		margin-bottom: 20rpx;
		display: flex;
		align-items: flex-start;

		.rank {
			color: $theme-color;
			font-size: 48rpx;
			font-weight: bold;
			margin: 0 10rpx;
		}

		.game-image {
			width: 150rpx;
			height: 150rpx;
			border-radius: 25rpx;
			object-fit: contain;
			margin: 0 10rpx;
		}

		.game-info {
			height: 150rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 0 20rpx;
			font-size: $font-size-base;
			gap: 10rpx;

			.game-name {
				font-size: 32rpx;
				font-weight: bold;
				display: flex;
				align-items: center;
				gap: 10rpx;
			}

			.game-desc {
				display: flex;
				color: #999;
				gap: 15rpx;

				.game-desc-item {
					display: flex;
					align-items: center;
					gap: 10rpx;
				}
			}
		}
	}
}
</style>
